package com.stox.ui.javafx.charting.model.uiunit;

import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;

import com.stox.indicator.VolumeByPrice.Unit;
import com.stox.ui.javafx.charting.model.plot.VolumeByPriceOverlayPlot;
import com.stox.ui.javafx.charting.widget.Chart;

public class VolumeByPriceUiUnit extends AbstractUiUnit<Unit, 
															Chart<VolumeByPriceOverlayPlot>, 
															VolumeByPriceUiUnit, 
															VolumeByPriceOverlayPlot> {

	public VolumeByPriceUiUnit(Unit model, VolumeByPriceOverlayPlot plot,
			int index) {
		super(model, plot, index);
	}

	@Override
	public void paint() {
		throw new UnsupportedOperationException();
	}
	
	public void paint(double max, double min){
		Canvas canvas = getPlot().getChart().getCanvas();
		GraphicsContext gc = canvas.getGraphicsContext2D();
		gc.setFill(Color.rgb(0,255,0,0.2));
		width = canvas.getHeight()/getPlot().getUiUnits().size();
		double y = canvas.getLayoutY() + canvas.getHeight() - (getIndex()+1)*width;
		double upLength = (getModel().getUpVolume() - min)*canvas.getWidth()/(max - min);
		
		gc.fillRect(canvas.getLayoutX(), y, upLength, width);
		gc.setFill(Color.rgb(255,0,0,0.2));
		double downLength = (getModel().getDownVolume() - min)*canvas.getWidth()/(max - min);
		gc.fillRect(canvas.getLayoutX() + upLength, y,downLength, width);
	}

}
